/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.cvut.fel.taskpro.business.manager;

import cz.cvut.fel.taskpro.business.imanager.IVersionBusiness;
import cz.cvut.fel.taskpro.business.isupport.IBusinessRuleValidator;
import cz.cvut.fel.taskpro.business.support.BusinessRuleException;
import cz.cvut.fel.taskpro.data.entity.AssignmentSubmit;
import cz.cvut.fel.taskpro.data.entity.VersionFile;
import cz.cvut.fel.taskpro.data.imanager.IVersionData;
import java.io.Serializable;
import java.util.Iterator;
import java.util.List;
import javax.annotation.security.DeclareRoles;
import javax.annotation.security.RolesAllowed;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.inject.Inject;

/**
 * This class implement #{@link IVersionBusiness} interface
 * @author Tom
 * 
 * @version 1.0. beta
 */
 @DeclareRoles({"admin", "kantor", "student"})
@Stateless
public class VersionBusiness implements IVersionBusiness, Serializable{

@Inject
 private IVersionData versionData;
@EJB
 private IBusinessRuleValidator businessRuleValidator;
 
 public VersionBusiness(){
     
 }
  @RolesAllowed({"kantor", "student"})
    @Override
    public List<VersionFile> getAllVersionFileByAssingment(AssignmentSubmit assignmentSubmit) {
 //  businessRuleValidator.validate(assignmentSubmit);
        return versionData.getAllVersionFileByAssignmentSubmit(assignmentSubmit);
    }
 @RolesAllowed({"kantor", "student"})
    @Override
    public void updateVersion(List<VersionFile> version) throws BusinessRuleException{
     Iterator versionIt=version.iterator();
     while(versionIt.hasNext()){
         VersionFile currVersionVile=(VersionFile)versionIt.next();
           businessRuleValidator.validateUpdate(currVersionVile);  
           versionData.updateVersionFile(currVersionVile);
     }
   
   
    }

   

   
}
